package com.zhuangwei.controller;

import com.zhuangwei.pojo.User;
import com.zhuangwei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author LeviCoder
 * @create 2019-03-09 22:18
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;

    @PostMapping("/add")
    public int save() {
        User user = new User();
        user.setId(3L);
        user.setUserName("zhuangwei");
        user.setAge(20);
        user.setBirthday(new Date());
        user.setCreated(new Date());
        user.setName("庄伟");
        user.setNote("测试springcloud微服务架构");
        user.setPassword("123456");
        user.setSex(1);
        int i = service.addUser(user);
        return i;
    }

    @GetMapping("/{id}")
    public User findById(@PathVariable("id") Long id) {
        return service.queryById(id);
    }
}
